﻿package common.tld;

import java.io.IOException;

import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import common.Globals;

/**
* @desc 自定义标签类 实现一个button权限的控制标签
*/
@SuppressWarnings("serial")
public class ImageTld extends TagSupport {
	//标签属性名称
	private String name = null;
	//标签属性权限
	private String purview = null;
	//标签属性单击事件
	private String onClick = null;
	//样式
	private String styleClass = null;
	//url
	private String url = null;
	//值
	private String value = null;
	
	
	//构造函数
	public ImageTld(){
	  
	}

	/* 标签初始方法 */
	@SuppressWarnings("static-access")
	public int doStartTag() throws JspTagException{
	      return super.EVAL_BODY_INCLUDE;
	}

	/* 标签结束方法 */
	@SuppressWarnings("static-access")
	public int doEndTag() throws JspTagException{
	      JspWriter out = pageContext.getOut();
	      purview = (String)pageContext.getSession().getAttribute(Globals.SESSION_PURVIEW);
	      String tagContent = "";
//	      if(name!=null && purview!=null && value!=null){
//	    	  if(purview.indexOf(","+name+",")!=-1) {
	    		  tagContent = "<div ";
	    		  if(styleClass!=null) tagContent += "class=\""+styleClass+"\">";
	    		  tagContent+= "<a ";
	    		  if(url!=null) tagContent += " href=\""+url+"\">";
	    		  if(onClick!=null && url==null) tagContent += " href=\"javascript:void("+onClick+")\">";
	    		  else if(onClick!=null && url!=null) tagContent+=" onclick=\""+onClick+"\" ";
	    		  tagContent+=value;
	    		  tagContent+= "</a> ";
	    		  tagContent+= "</div> ";
			     
//	    	  }
//	      }
	       
	      try{
	       //标签的返回值
	       out.println(tagContent);
	      }catch(IOException e){
	       e.printStackTrace();
	      }
	      return super.SKIP_BODY;
	}

	/* 释放资源 */
	public void release(){
	      super.release();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPurview() {
		return purview;
	}

	public void setPurview(String purview) {
		this.purview = purview;
	}

	public String getOnClick() {
		return onClick;
	}

	public void setOnClick(String onClick) {
		this.onClick = onClick;
	}

	public String getStyleClass() {
		return styleClass;
	}

	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}
